import requests


def get_openID(code):
    appID = 'wx5aa81556d9d2a4f0'
    appSecret = '92e066fc584f3edf12824932bb477f8c'
    # code = "0c3RQWkl2Gf6Qe4JbSml2n4pts0RQWkT"
    req_params = {
        'appid': appID,
        'secret': appSecret,
        'js_code': code,  # 前端发请求收集的临时登录凭证code
        'grant_type': 'authorization_code'
    }
    # 向微信官方请求openid
    wx_login_api = 'https://api.weixin.qq.com/sns/jscode2session'
    response_data = requests.get(wx_login_api, params=req_params)  # 向API发起GET请求
    return response_data.json()





if __name__ == '__main__':
    get_openID()
    print()